/*
 * Copyright (C) 2009 M. Hautle.
 * 
 * This file is part of TrackedBean.
 * 
 * TrackedBean is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * TrackedBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with TrackedBean. If not, see <http://www.gnu.org/licenses/>.
 */
package ch.trackedbean.validator;

import ch.trackedbean.common.*;

/**
 * Public interface of a validation engine.<br>
 * Implementations of this interface must be stateless and thread safe.
 * 
 * @author M. Hautle
 */
public interface IValidator {
	/**
	 * Checks if this validator does something usefull<br>
	 * Checks if simple properties validation or deptValidations will be processed by calling {@link #validate(Object)}.
	 * 
	 * @return True if this validator does something
	 */
	boolean doesSomething();

	/**
	 * Checks if the validator has {@link IBusinessValidator}s.
	 * 
	 * @return True if the validator does business validation
	 */
	boolean doesBusinessValidation();

	/**
	 * Validates the given bean (property and business content validaton).
	 * 
	 * @param bean The bean to validate
	 * @return The validaton result for the given bean
	 * @throws TechnicalException If the property doesen't exists or something went wrong
	 */
	ValidationResult validate(Object bean) throws TechnicalException;

	/**
	 * Validates the given bean.
	 * 
	 * @param bean The bean to validate
	 * @param context The context to use during the validation
	 * @return True if the validated object contains an error
	 * @throws TechnicalException If the property doesen't exists or something went wrong
	 */
	boolean validate(Object bean, IValidationContext context) throws TechnicalException;

	/**
	 * Validates the business part of the given bean.
	 * 
	 * @param bean The bean
	 * @return The validation result for the given bean
	 */
	ValidationResult validateBusinessPart(Object bean);

	/**
	 * Returns <code>null</code> if the property to validate was valid.<br>
	 * If the property was invalid a {@link String} describing the error will be returned.<br>
	 * This method validates only simple properties!
	 * 
	 * @param property The name of the property to validate
	 * @param bean The bean holding the property
	 * @return null if the property was valid, otherwise the error descriptions
	 * @throws TechnicalException If something went wrong
	 */
	IErrorDescription[] validate(String property, Object bean) throws TechnicalException;
}
